<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <p>{{ count }}</p>
      <button @click="count++">btn</button>
      <p>{{ obj }}</p>
      <button @click="obj.b = 5">btn2</button>
    </div>

    <script src="../../Vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          count: 1,
          obj: {
            a: 3,
            b: 4,
          },
        },
        // watch用于做监听
        watch: {
          count(val, oldVal) {
            console.log(val);
            console.log(oldVal);
          },
          // obj(val) {
          //   console.log(val);
          // },
          obj: {
            handler(val) {
              console.log(val);
            },
            // 深度的监听，可以去监听对象和数组
            deep: true,
            // 进入页面的先做一次监听
            immediate: true,
          },
        },
      });
    </script>
  </body>
</html>
